package org.zcl.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;

/**
 * @Package org.zcl
 * @PROJECT_NAME: question
 * @DESCRIPTION:
 * @USER: zhuchenglin
 * @DATE: 2022/5/29 15:11
 */
@Configuration
public class MyTemplate {

    //把每个方法都需要设置序列化器的步骤抽离出来
    //封装好，能够拿来即用
    @Bean
    public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory fc){
        StringRedisTemplate tp = new StringRedisTemplate(fc);
        //设置序列化器
        tp.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
        return tp;
    }
}

